import {addEquipment} from '../../api/pay'
import { scanfBluetooth } from '../../../utils/util'


Page({
    data: {
        id:'',
        name:''
    },
    onLoad: function (options) {
        console.log(options,'options')
        const {id,name} = options
        this.setData({
            id:id,
            name:name
        })

        this.scanf()
    },
    scanf(){
        scanfBluetooth().then(res=>{
            addEquipment({
                remark:this.data.name,
                id:this.data.id,
                macAddressList: res
            }).then(res=>{
                console.log(res,'resres')
                if(res.isSuccess){
                    wx.navigateTo({
                        url:'/packagePay/pages/device-success/device-success?type=' + 'success' + '&title=添加成功' + '&msg=' + res.msg
                    })
                }else{
                    wx.navigateTo({
                        url:'/packagePay/pages/device-success/device-success?type=' + 'warn' + '&title=添加失败' + '&msg=' + res.msg
                    })
                }
            }) 
        },(err)=>{
            console.log(err)
            setTimeout(()=>{
                wx.navigateTo({
                    url:'/packagePay/pages/device-success/device-success?type=' + 'warn' + '&title=添加失败' + '&msg=' + err
                })
            },2000)
        })
    },
    huoqu(){
        // wx.openBluetoothAdapter({
        //     success: (res) => {
        //         //搜索iBeacon设备
        //         wx.startBeaconDiscovery({
        //             uuids:[''],
        //             success(res) {
        //                 console.log(res,'成功')
        //             },
        //             complete(res){
        //                 console.log(res,'成功或失败')
        //             },
        //             fail(res){
        //                 console.log(res,'失败')
        //             }
        //         })
        //     },
        //     fail: () => {
        //         wx.showModal({
        //             title: '提醒',
        //             content: '请先打开您的手机蓝牙，打开后重新进入小程序',
        //         })
        //     }
        // })
        // addEquipment({
        //     remark:this.data.name,
        //     id:this.data.id,
        //     macAddressList:['121212']
        // }).then(res=>{
        //     console.log(res,'resres')
        //     if(res.isSuccess){
        //         wx.navigateTo({
        //             url:'/packagePay/pages/device-success/device-success?type=' + 'success' + '&title=添加成功' + '&msg=' + res.msg
        //         })
        //     }else{
        //         wx.navigateTo({
        //             url:'/packagePay/pages/device-success/device-success?type=' + 'warn' + '&title=添加失败' + '&msg=' + res.msg
        //         })
        //     }
        // })

    }
})